# 修改默认编码
from typing import Optional
from typing import List
import pytest_study
from pytest_study.Calculator.pythoncode.Calculator import Calculator


@pytest_study.fixture(scope="class")
def get_calc():
    calc = Calculator()
    yield calc
    print("结束测试")

@pytest_study.fixture(autouse=True)
# autouse 自动应用激活
def get_calcu():
    print("开始计算")
    yield
    print("结束计算")

def pytest_runtest_setup(item: "Item") -> None:
    print("hook : setup")


def pytest_runtest_teardown(item: "Item", nextitem: Optional["Item"]) -> None:
    print("teardwn")


def pytest_collection_modifyitems(
        session: "Session", config: "Config", items: List["Item"]
) -> None:
    print(items)
    for item in items:
        item.name = item.name.encode('utf-8').decode('unicode-escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode-escape')
    items.reverse()

# @pytest_study.fixture(scope="session", autouse=True)
# def manage_logs(request):
#     """Set log file name same as test name"""
#     now = time.strftime("%Y-%m-%d %H-%M-%S")
#     log_name = 'output/log/' + now + '.logs'
#
#     request.config.pluginmanager.get_plugin("logging-plugin") \
#         .set_log_path(log_name)